package com.um.jdy.app.charge.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alipay.api.AlipayApiException;
import com.um.jdy.app.charge.entity.dto.*;
import com.um.jdy.app.charge.entity.vo.OrderItemVO;
import com.um.jdy.app.charge.manager.EBoxOrderManager;
import com.um.jdy.app.charge.manager.OrderManager;
import com.um.springboot.starter.annotation.ActionLogRequired;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/v1/order/charge/ebox")
@Api(tags = "充电订单-充电柜")
@Validated
public class EBoxOrderController {

    @Autowired
    OrderManager orderManager;

    @Autowired
    EBoxOrderManager eBoxOrderManager;

    @SaCheckLogin
    @ApiOperation("开始充电")
    @PostMapping("start")
    public Response start(@RequestBody @Valid EBoxStartParam param) {
        return Response.success(eBoxOrderManager.startCharge(param));
    }

    @SaCheckLogin
    @ApiOperation("取消充电")
    @PostMapping("cancel")
    public Response cancel(@RequestBody @Valid EBoxStopParam param) throws Exception {
        eBoxOrderManager.checkUserOrderExits(param.getOrderNo());
        eBoxOrderManager.cancelCharge(param.getOrderNo());
        return Response.success();
    }

    @SaCheckLogin
    @ApiOperation("结束充电")
    @PostMapping("stop")
    public Response stop(@RequestBody @Valid EBoxStopParam param) throws Exception {
        eBoxOrderManager.checkUserOrderExits(param.getOrderNo());
        eBoxOrderManager.stopCharge(param.getOrderNo());
        return Response.success();
    }

//    @SaCheckLogin
//    @ApiOperation("结束离线设备充电")
//    @PostMapping("stop_offline")
//    public Response stopOffline(@RequestBody @Valid EBStopParam param) throws Exception {
//        eBoxOrderManager.checkUserOrderExits(param.getOrderNo());
//        eBoxOrderManager.stopOfflineCharge(param.getOrderNo());
//        return Response.success();
//    }

    @SaCheckLogin
    @ApiOperation("开仓门")
    @PostMapping
            ("open_door")
    public Response openDoor(@RequestBody @Valid EBoxOpenParam param) throws  Exception {
       return eBoxOrderManager.openDoor(param.getCode(),param.getOrderNo());
    }




//    @ActionLogRequired
//    @RequestMapping("wxpay/notify/{com_id}")
//    public Response wxPayNotify(HttpServletRequest request, @PathVariable String com_id) {
//        eBoxOrderManager.wxPayNotify(request, com_id);
//        return Response.success();
//    }
//
//    @ActionLogRequired
//    @RequestMapping(value = "alipay/notify")
//    @ResponseBody
//    public String alipayNotify(HttpServletRequest request) throws AlipayApiException {
//        eBoxOrderManager.aliPayNotify(request);
//        return "success";
//    }

    @ApiOperation("待支付订单支付")
    @PostMapping("pay")
    public Response orderPay(@RequestBody @Valid EBoxOrderPayParam param) throws  Exception {
        eBoxOrderManager.orderPay(param.getOrderNo());
        return Response.success();
    }

}
